package cn.wolfcode.trip.app.web.controller;

import cn.wolfcode.trip.base.service.IAtWhoService;
import cn.wolfcode.trip.base.util.JSONResult;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.HashMap;
import java.util.Map;

/**
 * 专门对@我的进行处理
 */
@Controller
@RequestMapping("/atwho")
public class AtWhoController {


    @Autowired
    private IAtWhoService service;


    /**
     * 展示所有未读的@
     *
     * @param
     * @return
     */
    @GetMapping("/listAll")
    @ResponseBody
    public Object listAllNoRead(Long id) {
        PageInfo info = service.selectAllNoReadAt(id);
        return info;
    }


    /**
     * 用于我的消息页面的回显,有几个@
     */
    @GetMapping("/count")
    @ResponseBody
    public Object count(Long id) {
        int num = service.countAtWho(id);
        //还有评论里的@
        int num1 = service.countAtComment(id);
        num = num + num1;
        Map map = new HashMap();
        map.put("num", num);
        return map;
    }

    @GetMapping("/read")
    @ResponseBody
    public Object read(Long id) {
        JSONResult jsonResult = new JSONResult();
        service.read(id);
        return jsonResult;
    }


    //展示所有未读的评论中@我饿
    @GetMapping("/listAllCommend")
    @ResponseBody
    public Object listAll(Long id) {
        PageInfo info = service.listAllNoReadCommend(id);
        return info;
    }

    /**将读过的评论at修改成已读
     * @param id
     * @return
     */
    @GetMapping("/readCommentAt")
    @ResponseBody
    public Object readComment(Long id) {
        JSONResult jsonResult = new JSONResult();
        service.readComment(id);
        return jsonResult;
    }





}
